// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LoginDlg.h"
#include "LoginView.h"
#include "ControlEx/DrawableBackground.h"

#define LOGINDLG_WIDTH		400
#define LOGINDLG_HEIGHT		300

// CLoginDlg dialog
//
//CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
//	: CDialog(CLoginDlg::IDD, pParent)
//{
//
//}
//
//CLoginDlg::~CLoginDlg()
//{
//}

//void CLoginDlg::DoDataExchange(CDataExchange* pDX)
//{
//	CDialog::DoDataExchange(pDX);
//}


//BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//END_MESSAGE_MAP()


// CLoginDlg message handlers

LRESULT CLoginDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CForUIDialog::OnInitDialog(uMsg, wParam, lParam, bHandled);

	// register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	UIAddChildWindowContainer(m_hWnd);

	//CUIConfig *pUIconfig = CUIConfig::GetUIConfigInstance();
	CCtrlBuilder  *pBuilder = this->GetCtrlBuilder();
	m_pLoginView = new CLoginView(this);
	pBuilder->Create(m_pLoginView, UIRect(10, 10, 20, 20), L"CLoginView");
	//m_pToolbar->ShowWindow(SW_SHOW);

	CDrawableObjectPtr imgBg = CDrawableObjectPtr(new CDrawableBackground(L"\\resource\\dlg_title.png", Color(254, 238,241,248), Color(254, 99,99,99), true, true));
	pBuilder->SetWndLayered(imgBg);
	pBuilder->SetWindowLayer(false);
	SetWindowPos(NULL, 0,0, LOGINDLG_WIDTH, LOGINDLG_HEIGHT, SWP_NOMOVE|SWP_NOZORDER);
	pBuilder->SetDispSize(LOGINDLG_WIDTH, LOGINDLG_HEIGHT);

	//m_editUrl.Create(m_hWnd, UIRect(9,125,193,145), NULL, WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL, WS_EX_CLIENTEDGE, IDC_EDIT_URL);
	CenterWindow();

	pBuilder->RePaint();
	return TRUE;
}

LRESULT CLoginDlg::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// unregister message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->RemoveMessageFilter(this);
	pLoop->RemoveIdleHandler(this);

	delete m_pLoginView;
	m_pLoginView = NULL;

	return 0;
}

LRESULT CLoginDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	EndDialog(wID);
	return 0;
}

LRESULT CLoginDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	m_pLoginView->onClickOK();
	return 0;
}

LRESULT CLoginDlg::OnKeyMsg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	_ATL_MSG msg(m_hWnd, uMsg, wParam, lParam);
	return TranslateMessage(&msg);
	return OnChar(uMsg, wParam, lParam, bHandled);
}
